package com.yh.jdk;

import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class TargetTest {
    @Test
    public void test(){
        Target target = new Target();
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?> [] interfaces = target.getClass().getInterfaces();
        InvocationHandler invocationHandler = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("练习时长2年半前");
                Object target1 = method.invoke(target, args);
                System.out.println("练习时长2年半后");
                return target1;
            }
        };
        TargetInterface targetInterface = (TargetInterface) java.lang.reflect.Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
        targetInterface.method();
    }
}
